﻿#if UNITY_EDITOR
#if !SHOWALLXLSXASSET
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Editor绘制
/// </summary>
[CustomEditor(typeof(XlsxDbTable), true)]
class ESF_XLSX_Editor_Draw : Editor
{
    Dictionary<int, ESF_AliasTooltipAttribute> mLangDisplay = typeof(enESF_LanguageClassify).ESF_ValueToAttribute<ESF_AliasTooltipAttribute>(); 
    XlsxDbTable mXlsxDbTable;
    ESF_CollectAsset_XLSX mXlsx;
    private void OnEnable()
    {
        if (target != null)
        {
            mXlsxDbTable = (XlsxDbTable)target;
            mXlsx = new ESF_CollectAsset_XLSX(mXlsxDbTable.tablePath);
            mXlsx.Resolve();
        }
    }

    public override void OnInspectorGUI()
    {
        if (mXlsx != null)
        {
            GUILayout.Label($"表路径：{mXlsxDbTable.tablePath}");
            GUILayout.Label($"表语言：{mLangDisplay[mXlsxDbTable.tableLanguage].alias}【{(enESF_LanguageClassify)mXlsxDbTable.tableLanguage}】");

            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Search.ESF_ToAlias()}{ESF_enGUIDisplayWord.Data.ESF_ToAlias()}"))
            {
                EditorWindowSFXLSXConfigQueryData query = EditorWindow.GetWindow<EditorWindowSFXLSXConfigQueryData>();
                query.SetData(mXlsx);
                query.Show();
            }
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Resolver.ESF_ToAlias()} 表架构"))
            {
                ESF_Logic.ResolveXlsxSchema(mXlsx);
            }
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Build.ESF_ToAlias()} 表脚本"))
            {
                ESF_Logic.BuildXlsxScript(mXlsx);
            }
            if (GUILayout.Button($"{ESF_enGUIDisplayWord.Build.ESF_ToAlias()} 数据库"))
            {
                if (mXlsx != null)
                {
                    ESF_Logic.BuildXlsxDbMaster(mXlsx);
                }
            }
            if (mXlsxDbTable != null)
            {
                if (mXlsxDbTable.rows.Length > 0)
                {
                    EditorGUILayout.LabelField($"{mXlsxDbTable.name} [{mXlsxDbTable.rows.Length}] rows");
                }
                else
                {
                    EditorGUILayout.LabelField($"{mXlsxDbTable.name} [0] rows");
                }
            }
        }
    }
}
#endif
#endif